using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Boomlagoon.JSON;

public class DataContainerParser<T>
	where T : AbstractDataComponent, new()
{
	public static void parseDataContainer (JSONObject dataContainerJsonObj , DataContainer<T> dataContainer , AbstractDataComponentParser dataComponentParser)
	{
		JSONArray jsonArray = dataContainerJsonObj.GetArray("groupIds");
		for (int i = 0 ; i < jsonArray.Length ; i++)
		{
			dataContainer.AddGroupId(jsonArray[i].Str);
		}

		JSONObject dataComponentsJsonObj = dataContainerJsonObj.GetObject("components");
		foreach (KeyValuePair<string,JSONValue> pair in dataComponentsJsonObj)
		{
			AbstractDataComponent dataComponent = dataComponentParser.parseDataComponent(pair.Key , pair.Value.Obj);
			dataContainer.AddData((T)dataComponent);
		}
	}
}
